package com.geh.learn.files;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by gehui on 2017/3/30.
 */
public class ListFilesTest {
    public static void main(String[] args) throws IOException {
        final List<Path> files=new ArrayList<>();
        // 遍历一个文件夹下的所有文件，包括自文件夹下面的文件
        try {
            Files.walkFileTree(Paths.get("/Users/gehui/work/gitproject/jdk-learn"), new SimpleFileVisitor<Path>(){
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    if(!attrs.isDirectory()){
                        files.add(file);
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }


        files.forEach(System.out::println);
    }
}
